#---------------------------------------
# Tuan
#---------------------------------------
class Admin::BookCateController < ApplicationController
  # specific layout
  layout 'admin/application'
  
  def index
    @book_cates = BookCategory.paginate(:page => params[:page], :per_page => 10)
  end

  # add new book_cate
  def new
    @book_cate = BookCategory.new
  end
  def create
    @book_cate = BookCategory.new(params[:book_cate])
    if @book_cate.save
      flash[:notice] = "Create successfully"
      redirect_to :controller => "admin/book_cate", :action => "view", :id => @book_cate.id
    else
      flash[:notice] = "There are some errors"
      render "new"
    end
    
  end
  
  # edit book_cate
  def edit
    @book_category = BookCategory.find(params[:id])
  end
  def update
    @book_category = BookCategory.find(params[:id])
    if @book_category.update_attributes(params[:book_category])
      redirect_to :controller => "admin/book_cate", :action => "view", :id => @book_category.id
    else
      render "edit"
    end
  end
  
  # view the book_cate info
  def view
    @book_cate = BookCategory.find(params[:id])
  end
  
  # delete the book_cate
  def delete
    @book_cate = BookCategory.find(params[:id])
    @book_cate.destroy
    
    redirect_to :controller => "admin/book_cate", :action => "index"
  end
end